package cn.yh.register.order.controller;

import cn.yh.register.common.result.Result;
import cn.yh.register.enums.OrderStatusEnum;
import cn.yh.register.model.order.OrderInfo;
import cn.yh.register.order.service.OrderService;
import cn.yh.register.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "订单管理接口")
@RestController
@RequestMapping("/admin/order/orderInfo")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("分页查询顶单列表")
    @GetMapping("/{page}/{limit}")
    public Result<IPage<OrderInfo>> index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "orderCountQueryVo", value = "查询对象", required = false) OrderQueryVo orderQueryVo) {
        IPage<OrderInfo> pageList = orderService.findPageList(page, limit, orderQueryVo);
        return Result.ok(pageList);
    }


    @ApiOperation(value = "获取订单状态列表")
    @GetMapping("/getStatusList")
    public Result<List<Map<String, Object>>> getStatusList() {
        List<Map<String, Object>> statusList = OrderStatusEnum.getStatusList();
        return Result.ok(statusList);
    }


    @ApiOperation("获取订单详情")
    @GetMapping("/show/{id}")
    public Result<Map<String, Object> > show(@ApiParam(name = "orderId", value = "订单id", required = true)
                       @PathVariable Long id) {
        Map<String, Object> show = orderService.show(id);
        return Result.ok(show);
    }

}
